package com.kajespero.dao.commons.impl;

import java.lang.reflect.ParameterizedType;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.kajespero.dao.commons.DAO;
import com.kajespero.dao.commons.PersistManager;
import com.kajespero.vo.VO;

public abstract class AbstractDAO<T extends VO> implements DAO<T>{
	
	private static final Log LOG = LogFactory.getLog(AbstractDAO.class);
	
	private static final PersistManager INSTANCE = new PersistManagerJDOImpl();
	
	private Class<T> clazz;


	@Override
	public PersistManager getIntance() {
		return INSTANCE;
	}

	@Override
	public Class<T> getBeanClass() {
		if(this.clazz == null){
			initBeanClass();
		}
		return this.clazz;
	}
	
	@SuppressWarnings("unchecked")
	private void initBeanClass(){
		ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
		LOG.debug("class test == " + getClass());
		clazz = (Class<T>) parameterizedType.getActualTypeArguments()[0];
	}
	

}
